﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>赛果竞猜</title>
<!-- InstanceEndEditable -->
<link href="../css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="../css/date-time.css" rel="stylesheet" type="text/css"/>

<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" href="../css/default.css" />
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<!-- <!-- <script type="text/javascript" src="../js/common.js"></script>
 -->
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
 <script type="text/javascript" src="../js/common-2.js"></script>
<script type="text/javascript" src="../js/qmsk-1.2.js"></script> -->
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/teamSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/date-time.min.js"></script>
<script type="text/javascript" src="../js/date-time.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script> 
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<style type="text/css">
#window_change p label span img {
	border: 1px solid #CCCCCC;
	height: 90px;
	vertical-align: middle;
	width: 70px;
}
</style>
<script type="text/javascript">
	$(function() {
		   $('#beginTime').datetimepicker({
			      language: 'pt-BR'
			    });
		   $('.doubledate').kuiDate({
				className:'doubledate',
				isDisabled: "0"  // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
			});
		   $('#dtBegin').val(getToday());
			 $('#dtEnd').val(getToday());
		 _htmlUploadUrl="apply";
		 _indexUrl="indexUrl";
		 _htmlTitle='title';
	});
	$(function() {
		initImage()
	})



	function popPoint(id) {
		art.dialog({
			fixed : true,
			lock : true,
			content : "确认删除该条数据？",
			icon : 'question',
			ok : function() {
				deleteInfo(id)
			},
			cancel : true
		});
	}
	//查询
	function searchApply() {
		getTryDriverList(1);
	}
	function getTryDriverList(index) {
		if (IsEmpty(index)) {
			index = 1
		}

		var group = $("#group").val();
		var dtBegin = $("#dtBegin").val()
		var dtEnd = $("#dtEnd").val()
		var params = {
			'status' : group,
			'dtBegin':dtBegin,
			'dtEnd':dtEnd
		}
		var dt = _findInfo("../teamGame/find/teamGameList/" + (index - 1) + "/10",
				params);
		if (IsNotEmpty(dt) && dt.state == 0) {
			$("#memberList tbody").empty()

			for ( var i = 0; i < dt.result.data.length; i++) {
				var htm = "<tr>"
					htm += "<td>" + _getStringOfJson(i, dt, "name") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "zname") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "kname") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "gameStaName") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "beginTime") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "staName") + "</td>"
				var id = _getIntOfJson(i, dt, "id")
				htm += "<td> <input type='button' class='common_btn' value='修改' class='btn' onclick='setting("
						+ id + ")'>&nbsp;<input class=\"del\" type=\"button\" onclick=\"setReult("+id+")\" value=\"设置结果\"><input class=\"del\" type=\"button\" onclick=\"lookInfo("+id+")\" value=\"查看竞猜\"><input class=\"del\" type=\"button\" onclick=\"delApply("+id+")\" value=\"删除\"> </td>"
				htm += "</tr>"
				$("#memberList tbody").append(htm)
			}
			/* 		_loadInfo(dt, "memberList", param)
			 */
			$("#memberList tbody tr").each(function() {

			})
			_loadPage("pager", index, 10, dt, getTryDriverList, "NoResult");
			$("#sup").html("共" + dt.result.len + "条");
		}
	}

	//改变女主播
	function setting(id) {
		resForm();
		var url = " ../teamGame/find/applyById";
		$("#upid").val(id);
		$("#doflag").val(2)
		if (id > 0) {
			$.get(url, {
				"id" : id
			}, function(g) {
				var rst = JSON.parse(g);
				console.log(rst);
				$("#status").val(_getStringOfJson(0, rst, 'status'));
				$("#gameName").val(_getStringOfJson(0, rst, 'name'));
				$("#time").val(_getStringOfJson(0, rst, 'beginTime'));
				var zhtm = "<option value='"+_getStringOfJson(0, rst, 'zId') + "'>"+_getStringOfJson(0, rst, 'zname')+"</option>"
				var khtm = "<option value='"+_getStringOfJson(0, rst, 'kId') + "'>"+_getStringOfJson(0, rst, 'kname')+"</option>"
				$("#zId").html(zhtm)
				$("#kId").html(khtm)
			});
			
			$("#yinying1,#window_change").show();
			addMargin($("#window_change"));

		}
	}
	
	function save(){
		var doflag= $("#doflag").val()
		if(doflag==1){
			insertApply()
		}else{
			updateApply()
			}
	}
//更新
	function updateApply() {
		var upid = $("#upid").val();
		var zId=$("#zId").val();		
		var kId=$("#kId").val();		
		var gameName=$("#gameName").val();		
		var gameStatus=$("#status").val();
		var gameType=$("#gameType").val();
		var beginTime = $("#time").val()
		if(IsEmpty(gameName)){
			alertErrorMessage("请填写比赛名称");;
			return false;
		}
		if(IsEmpty(beginTime)){
			alertErrorMessage("请选择开赛时间");;
			return false;
		}
		if(IsEmpty(zId)){
			alertErrorMessage("请选择队一");;
			return false;
		}
		if(IsEmpty(kId)){
			alertErrorMessage("请选择队二");;
			return false;
		}
		var heads = new Array("status","zId","kId","name","beginTime","gameType","id");
		var datas = new Array( gameStatus,zId,kId,gameName,beginTime,gameType,upid);
		var parser = new Object();
		var jsonParserStr = null;//定义空头字符串
		if (IsNotEmpty(datas)) {
			addToParser(heads, datas, "edit", parser);
			jsonParserStr = JSON.stringify(parser);
		}

		var url = " ../teamGame/edit";
		$.post(url, {
			"data" : jsonParserStr
		}, function(data) {
			$("#close_this").attr("disabled", false);
			var dt = JSON.parse(data);
			if(dt.result>0){
					
				$("#window_change").hide();
				$("#yinying1").hide();
				art.dialog({fixed:true, lock: true,content:'修改成功',icon:'succeed',ok:true});
				searchApply();
			}else{
				art.dialog({fixed:true, lock: true,content:'修改失败',icon:'error',ok:true});
			}
			console.log(data);
			//saveOwnShopIds();
			
		});

	}
	
	//删除
	function delApply(id){
		var url = " ../teamGame/del";
		//$("#upid").val(id);
		if (id > 0) {
			$.get(url, {
				"id" : id
			}, function(g) {
				console.log(g);
				var rst = JSON.parse(g);
				if(rst.state==0){
					searchApply();
					art.dialog({fixed:true, lock: true,content:'删除成功',icon:'success',ok:true});
				}
				console.log(rst);
				//$("#Name").val(_getStringOfJson(0, rst, 'name'))
			});
		}
	}
	function showInsert(){
		$("#window_add").show();
		addMargin($("#window_add"));
	}
	
	function resForm(){
		$("#gameName").val("");
		$("#time").val("");
		$("#zId").html("");
		$("#kId").html("");
		$("#uupload").val("");
	}
	
	
	function toAdd(){
		resForm();
		$("#doflag").val(1)
		$("#window_change,#yinying1").show();
		addMargin($("#window_change"));
	}
	
	function insertApply(){
		var zId=$("#zId").val();		
		var kId=$("#kId").val();		
		var gameName=$("#gameName").val();		
		var gameStatus=$("#status").val();
		var gameType=$("#gameType").val();
		var beginTime = $("#time").val()
		if(IsEmpty(gameName)){
			alertErrorMessage("请填写比赛名称");;
			return false;
		}
		if(IsEmpty(beginTime)){
			alertErrorMessage("请选择开赛时间");;
			return false;
		}
		if(IsEmpty(zId)){
			alertErrorMessage("请选择队一");;
			return false;
		}
		if(IsEmpty(kId)){
			alertErrorMessage("请选择队二");;
			return false;
		}
		
		var heads = new Array("status","zId","kId","name","beginTime","gameType");
		var datas = new Array( gameStatus,zId,kId,gameName,beginTime,gameType);
		var parser = new Object();

		var jsonParserStr = null;//定义空头字符串
		if (IsNotEmpty(datas)) {
			addToParser(heads, datas, "add", parser);
			jsonParserStr = JSON.stringify(parser);
		}
		
		$("#close_this").attr("disabled", true);
		var url = " ../teamGame/insert";
		$.post(url, {
			"data" : jsonParserStr
		}, function(data) {
			$("#close_this").attr("disabled", false);
			var dt = JSON.parse(data);
			//alert(dt.result)
			if(dt.state==0){
				var id = getHeadIndexValue(0, dt, "id");
				 $("#window_change").hide();
				$("#yinying1").hide();
				searchApply();
				art.dialog({fixed:true, lock: true,content:'添加成功',icon:'success',ok:true});
	
			}else{
				art.dialog({fixed:true, lock: true,content:'添加失败',icon:'error',ok:true});
			}
			//saveOwnShopIds();
		});

	}
	/* function openImage(id){
		window.location.href=id;
		
	} */
	function initImage() {
		Shadowbox.init();
		window.openImage = function(url) {
			Shadowbox.open({
				content : url,
				player : 'img'
			});
		};
	}
	
	/* function getHtmlUrl(html) {
		var url = '';
		$.ajax({
			type : "post",
			async : false,
			datatype : "JSON",
			url : "../htmlUtils/htmlFileGender",
			data : {
				'html' : html
			},
			success : function(rst) {
				if ( typeof rst === "string") {
					rst = JSON.parse(rst);
				}
				var response = new qmsk.Response(rst);
				url = response.getValue("url");
			}
		});
		return url;
	}

	function generateHtmlUrl() {
		var html = editorHtml;
		var url = '';
		if (qmsk.isNotEmpty(html)) {
			url = getHtmlUrl(html);
		}
		alert(url);
	}
 */
	
 function lookInfo(pid){
	 pId = pid
	 $("#guess").hide()
	 $("#guessResult").show()
	 getGuessResultList(1)
 }
 
	function getGuessResultList(sdf) {
		if (IsEmpty(sdf)) {
			index2 = 1
		}else{
			index2 = sdf
		}
		var params = {
			'gId':pId
		}
		var dt = _findInfo("../teamGameGuess/find/teamGameGuessList/" + (index2 - 1) + "/10",
				params);
		if (IsNotEmpty(dt) && dt.state == 0) {
			$("#resultList tbody").empty()

			for ( var i = 0; i < dt.result.data.length; i++) {
				var htm = "<tr>"
				var CustomerName = _getSomeOfJson(i, dt, "CustomerName");
				if(IsEmpty(CustomerName)){
					CustomerName = '关注客户'
				}
				htm += "<td> "+CustomerName+"</td>"
				htm += "<td>" + _getStringOfJson(i, dt, "Mp") + "</td>"
				htm += "<td>" + _getStringOfJson(i, dt, "name") + "</td>"
				htm += "<td>" + _getStringOfJson(i, dt, "zName") +"vs"+ _getStringOfJson(i, dt, "kName")+ "</td>"
				
				var chooseStatus = _getIntOfJson(i, dt, "chooseStatus")
				var gameStatus = _getIntOfJson(i, dt, "gameStatus")
				var status = _getIntOfJson(i, dt, "status")
				var cho = null;
				if(chooseStatus==1){
					cho = "胜";
				}else if(chooseStatus == 2){
					cho = "平"
				}else if(chooseStatus == 3){
					cho = "负"
				}
				
				
				var result= null;
					htm += "<td>" +cho + "</td>"
				var id = _getIntOfJson(i, dt, "id")
				if (gameStatus ==0){
						htm += "<td> 未赛</td>"
							htm += "<td> </td>"
			}else {
					if(gameStatus == chooseStatus){
						htm += "<td> 正确</td>"
						if(status==0){
						htm += "<td> <input type='button' class='common_btn' value='送积分' class='btn' onclick='showSjf("+ id + ")'> </td>"
						}else{
							htm += "<td>已赠送积分 </td>"
						}
					}else{
						htm += "<td> 错误</td>"
							htm += "<td> </td>"
					}
					
				}
					
				
				htm += "</tr>"
				$("#resultList tbody").append(htm)
			}
			/* 		_loadInfo(dt, "memberList", param)
			 */
			
			_loadPage("pager2", index2, 10, dt, getGuessResultList, "NoResult2");
			$("#sup2").html("共" + dt.result.len + "条");
		}
	}
	
	
	function showSjf(id){
		art.dialog({fixed:true, lock: true,content:"确认给该用户赠送积分？",icon:'question',ok: function(){ sendInget(id) },cancel:true});
		}
	function sendInget(id){
		
		var dt = _insertInfo("../teamGameGuess/check", {'id':id})
		if(IsNotEmpty(dt)&&dt.state==0){
			getGuessResultList(index2)
		}
	}
	
	function goBack(){
		 $("#guess").show()
		 $("#guessResult").hide()
	
	}
	
	function setReult(id){
		$("#upid").val(id)
		var url = " ../teamGame/find/applyById";
		$("#upid").val(id);
		$("#doflag").val(2)
		if (id > 0) {
			$.get(url, {
				"id" : id
			}, function(g) {
				var rst = JSON.parse(g);
				console.log(rst);
				$("#gameStatus").val(_getStringOfJson(0, rst, 'gameStatus'));
				$("#zScroe").val(_getStringOfJson(0, rst, 'zScroe'));
				$("#kScroe").val(_getStringOfJson(0, rst, 'kScroe'));
			
			});
		$("#yinying1,#gameReslutShow").show();
		addMargin($("#gameReslutShow"));
		
		}
	}
	function saveResult (){
		var id = $("#upid").val()
		var gameStatus = $("#gameStatus").val()
		var zScore = $("#zScroe").val();
		var kScroe = $("#kScroe").val();
		if(!checkNumber(zScore, false, "比分", "zScroe")||!checkNumber(kScroe, false, "比分", "kScroe")){
			return false;
		}
		
		var heads = ["gameStatus","kScroe","zScroe","id"]
		var datas = [gameStatus,kScroe,zScore,id]
		
		var json = _getJsonParseEditStr(heads, datas);
		
		var dt = _editInfo("../teamGame/edit/editGameStatus", {'data':json})
		if(IsNotEmpty(dt)&&dt.state==0){
			$("#yinying1,#gameReslutShow").hide();
			searchApply();
		}
	}
	
	function toExper(){
		var params = {
				'gId':pId,
				'downType':1
			}
		window.location.href="../teamGame/down/csv/down?"+$.param(params)
		
	}
	
	function toExper2(){
			art.dialog({fixed:true, lock: true,content:"确认要推送信息吗？",icon:'question',ok: function(){ sendInfo(id)},cancel:true});
	}
	function sendInfo (){
		var params = {
				'id':pId,
			}
		
		var dt = _editInfo("../teamGameGuess/allCheck", params)
		if(IsNotEmpty(dt)&&dt.state==0){
			$("#yinying1,#gameReslutShow").hide();
			searchApply();
		}
	}
</script>
<!-- dateTime -->

</head>

<body>
<div id="yinying1"></div>

	<div id="window_change" class="member_search hideDiv"
		style="width: 520px;">
		<div class="closeTop">
			<span class="closeThe" onclick="closeParent($(this))"><img
				src="../images/close.png"></span>
		</div>
		 <input type="hidden" id="upid" />
		<input type="hidden" id="doflag">
		 <input type="hidden" id="shopflag">
			 <input type="hidden" id="defaultCflag">
			
			
			<div><p style="display:inline-block;">
			<label><span> 比赛名称：</span>
			 	<input id="gameName" class="reset" type="text">
			</label>
			<p style="display:inline-block;"><span>开赛时间：</span></p>
			<div class="well">
  <div id="beginTime" class="input-append date">
    <input id="time" data-format="yyyy-MM-dd hh:mm:ss" type="text"></input>
    <span class="add-on">
      <i data-time-icon="icon-time" data-date-icon="icon-calendar">
      </i>
    </span>
  </div>
</div>
</div>

			</p>
			<p>
			<label><span>队伍一：</span>
			 	<select id="zId" onclick="openTeamListPanel('zId')" >
						
				 </select>
			</label>
			<label><span>队伍二：</span>
			 	<select id="kId" onclick="openTeamListPanel('kId')" >
				
				 </select>
			</label>
			</p>
			<p>
			<label><span> 类型：</span>
			 	<select id="gameType" >
						<option value="0">小组赛</option>
						<option value="1">淘汰赛</option>
						
				 </select>
			</label>
			<label><span> 状态：</span>
			 	<select id="status" >
						<option value="0">使用</option>
						<option value="1">停用</option>
						
				 </select>
			</label>
			</p>	
			
		<input type="hidden" id="updateId"> <input type="hidden" id="upid" />
		
		<div class="submit_btn">
			<input type="button" value="保存信息" class="common_btn" id="close_this"
				onclick="save()">
		</div>
	</div>
	<div id="gameReslutShow" class="member_search hideDiv"
		style="width: 520px;">
		<div class="closeTop">
			<span class="closeThe" onclick="closeParent($(this))"><img
				src="../images/close.png"></span>
		</div>			
			
			<p>
			<label><span> 比赛结果：</span>
			 	<select id="gameStatus" >
						<option value="0">未赛</option>
						<option value="1">胜</option>
						<option value="2">平</option>
						<option value="3">负</option>
						
				 </select>
			</label>
			<span> 比分：</span>
			 	<input  id="zScroe" style="width: 40px;">: <input style="width: 40px;"  id="kScroe">
			 	

			
			</p>	
			
		<input type="hidden" id="updateId"> <input type="hidden" id="upid" />
		
		<div class="submit_btn">
			<input type="button" value="保存信息" class="common_btn" id="close_this"
				onclick="saveResult()">
		</div>
	</div>
	
	<div class="container" id="container">
		<div class="container_R fr" id="guess">
			<div class="place">世界杯赛果竞猜</div>
			<div class="member_search">

				<p>
					<!-- <span> <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">店面：</span>
        <select id="shopName" onclick="openShopListPanel(this)" disabled="disabled">
        </select> -->
					<!-- <span>起始日期：</span> <input type="text" readonly
						class="doubledate ipticon" id="dtBegin" /> <span>截止时间：</span> <input
						type="text" readonly class="doubledate ipticon" id="dtEnd" />
					 -->	<span>状态：</span>
				<select id="group" >
						<option value="">全部</option>
						<option value="0">使用</option>
						<option value="1">停用</option>
						
				 </select>
				  <span>起始日期：</span>
			        <input type="text" readonly class="doubledate ipticon"  id="dtBegin"/>
			        <span>截止时间：</span>
			        <input type="text" readonly class="doubledate ipticon" id="dtEnd"/>
				</p>
				<p>
					<input type="button" style="float: right;"  value="查询" class="btn" onclick="searchApply()">
				</p>				
			</div>

			<table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
				<caption>
					<strong>赛果竞猜列表 <span id="sup">共0条</span>
					</strong> 
						<input type="button" value="添加" class="common_btn addList" onclick="toAdd()">
				</caption>
				<thead>
					<tr>
						<th >比赛名称</th>
						<th>队一</th>
						<th >队二</th>
						<th >比赛结果</th>
						<th >开赛时间</th>
						<th >状态</th>
						<th >操作</th>
						
					</tr>
				</thead>
				<tbody>

				</tbody>
			</table>
			<div id="NoResult" class="Nothing"
				style="text-align: center; display: none;">无符合条件的数据！</div>
			<div id="pager" style="float: right;"></div>
		</div>
		
		
		<div class="container_R fr" style="display: none;" id="guessResult">
			<div class="place">
							<span>
				竞猜结果
				<a class="goHome" href="javaScript:void(0)" onclick="goBack()">返回</a>
				</span>
			</div>
			<div class="member_search">

		
				
			</div>

			<table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="resultList">
				<caption>
					<strong>竞猜结果列表 <span id="sup2">共0条</span>
					</strong>
					<input class="common_btn" type="button" onclick="toExper2()" value="发送消息"> 
					<input class="common_btn" type="button" onclick="toExper()" value="导出数据"> 
				</caption>
				<thead>
					<tr>
						<th >客户姓名</th>
						<th>电话</th>
						<th>比赛</th>
						<th>队伍</th>
						<th>竞猜</th>
						<th>状态</th>
						<th >操作</th>
						
					</tr>
				</thead>
				<tbody>

				</tbody>
			</table>
			<div id="NoResult2" class="Nothing"
				style="text-align: center; display: none;">无符合条件的数据！</div>
			<div id="pager2" style="float: right;" class="shopPager"></div>
		</div>
		<div class="fc"></div>
	</div>
	<!-- InstanceEndEditable -->
	<script type="text/javascript" src="../js/header.js"></script>
	<script type="text/javascript" src="../js/left.js"></script>
	<script type="text/javascript" src="../js/footer.js"></script>
	
	<script type="text/javascript">
		clearThis("absoluteTxt");
		showTab(1, 1);
	</script>
</body>
<!-- InstanceEnd -->
</html>
